package model

import (
	"time"
)

type Notice struct {
	Id      int       `xorm:"INT(11) PK AUTOINCR comment('主键')" json:"id"`
	Text    string    `xorm:"TEXT comment('公告')" json:"text"`
	Status  bool      `xorm:"default true" json:"status"`
	Created time.Time `xorm:"DATETIME INDEX" json:"created"`
	Updated time.Time `xorm:"DATETIME" json:"updated"`
}

// NoticeGet  单条
func NoticeGet(id int) (*Notice, bool) {
	mod := &Notice{}
	has, _ := db.ID(id).Get(mod)
	return mod, has
}

// NoticeAll 所有
func NoticeAll() ([]Notice, error) {
	mods := make([]Notice, 0, 4)
	sess := db.NewSession()
	defer sess.Close()
	sess.Where("status = ?", true)
	err := sess.Desc("id").Find(&mods)
	//err := db.Desc("created").Find(&mods)

	return mods, err
}
